package userclasses;

import javax.microedition.location.*;

/**
 *
 * @author Daniel Lingenfelter
 */
public class Request {
    int PassValue;
    int PickValue;
    int DropValue;
    double latitude, longitude;

    Request(int a, int b, int c){
        PassValue = a;
        PickValue = b;
        DropValue = c;
    }
    Response getResponse() {
        Response x = null;
        //In lieu of connection, use sample data.
        switch (PassValue) {
            case 1:
                //GPS option
                this.getGPS();
                x = new Response(40000, "#0053", null, 80000);
                break;
            case 2:
                //Station 1
                x = new Response(70000, "#0037", null, 80000);
                break;
            case 3:
                //Station 2
                x = new Response(50000, "#0046, #0081", null, 80000);
                break;
            default:
                //error
        }
        return x;
    }
    void getGPS() {
        Coordinates x = null;
        Criteria c = new Criteria();
        c.setHorizontalAccuracy(5);
        c.setVerticalAccuracy(5);
        try {
            LocationProvider lp = LocationProvider.getInstance(c);
            if(lp == null){
                lp = LocationProvider.getInstance(null);
            }
            Location gpsLoc = lp.getLocation(-1);
            x = gpsLoc.getQualifiedCoordinates();
        } catch (LocationException lex){
            //Unable to retrieve location or timeout
            latitude = 0;
            longitude = 0;
        } catch (InterruptedException iex){
            latitude = 0;
            longitude = 0;
        }
        latitude = x.getLatitude();
        longitude = x.getLongitude();
    }
}
